<template>
  <div>
    <el-table
      :data="tableData"
      style="width: 100%"
      :row-class-name="tableRowClassName"
    >
      <el-table-column prop="id" label="序号" align="center" width="50">
      </el-table-column>
      <el-table-column prop="name" label="用户账户" align="center" width="120">
      </el-table-column>
      <el-table-column
        prop="username"
        label="用户昵称"
        align="center"
        width="180"
      >
      </el-table-column>
      <el-table-column
        prop="consumption"
        label="消费金额"
        align="center"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="quantity"
        label="订单数量"
        align="center"
        width="120"
      >
      </el-table-column>
      <el-table-column
        prop="number"
        label="订单编号"
        align="center"
        width="180"
      >
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableData: [
        {
          id: 1,
          name: 124567987, //用户账户
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 2,
          name: "家电清洗",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 3,
          name: "深度保洁",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 4,
          name: "放心搬家",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 5,
          name: "做饭阿姨",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 6,
          name: "钟点工",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 7,
          name: "清洁保养",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 8,
          name: "家电维修",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
        {
          id: 9,
          name: "洗衣洗鞋",
          username: "就很好", //用户昵称
          consumption: 234, //消费金额
          quantity: 1, //订单数量
          number: 478412871130305, //订单编号
        },
      ],
    };
  },
  methods: {
    tableRowClassName({ row, rowIndex }) {
      if (rowIndex % 3 === 1) {
        return "warning-row";
      } else if (rowIndex % 3 === 2) {
        return "success-row";
      }
      return "";
    },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    },
  },
};
</script>

<style lang="less">
.el-table .warning-row {
  background: oldlace;
}

.el-table .success-row {
  background: #f0f9eb;
}
</style>
